package com.mapper;

import com.POJO.Grade;
import java.util.List;

import com.POJO.GradeAdd;
import org.apache.ibatis.annotations.*;

/**
 * @Package com.mapper
 * @Date 2024-05-23 11:36
 * 分数相关数据库操作
 */
@Mapper
public interface GradeMapper {
    // 根据学生ID获取其所有成绩
    @Select("SELECT * FROM grades WHERE student_id = #{studentId}")
    List<Grade> getGradesByStudentId(int studentId);

    // TODO: 新增成绩
    @Insert("INSERT INTO grades (student_id, subject_id, grade) VALUES (#{studentId}, #{subjectId}, #{grade})")
    @Options(useGeneratedKeys = true, keyProperty = "gradeId")
    void insertGrade(GradeAdd grade);

    // 更新成绩
    @Update("UPDATE grades SET grade = #{grade} WHERE student_id = #{studentId}")
    void updateGrade(@Param("grade") double grade, @Param("studentId") int studentId);

    // 删除成绩
    @Delete("DELETE FROM grades WHERE grade_id = #{gradeId}")
    void deleteGrade(int gradeId);
    //ADD connect Object to DB
    @Select("SELECT * FROM grades WHERE subject_id = #{subjectId}")
        List<Grade> getGradesBySubjectId(@Param("subjectId") int subjectId);
}
